package xuli.dao.impl;


import entity.User;
import entity.User_Inf;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import util.C3P0Util;
import xuli.dao.UserDao;

import java.sql.SQLException;


/**
 * @author xuli
 */
public class UserDaoImpl implements UserDao {

    private QueryRunner queryRunner = new QueryRunner(C3P0Util.getDataSource());

    @Override
    public User_Inf findById(Integer userId) {

        String sql = "select * from user_inf where userId=?";
        User_Inf userInf = null;

        try {
            userInf = queryRunner.query(sql, new BeanHandler<>(User_Inf.class), userId);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return userInf;

    }

    @Override
    public User queryUserByLoginNameAndPassword(String loginName, String loginPwd) {
        User user = null;
        String sql = "select * from user_login where username = ? and password=?";
        try {
            user = queryRunner.query(sql, new BeanHandler<User>(User.class),loginName,loginPwd);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return user;
    }
}
